{extend name="base" /}
{block name="body"}
<div class="layui-card">
	<div class="layui-card-header">
		<form action="{:url('admin/metadata/importLogIndex')}" class="layui-form" method="get">
			<div class="layui-form-item">
				<div class="layui-inline">
					批次号
				</div>
				<div class="layui-inline">
					<input type="text" name="batchNo" value="{:input('batchNo')}" autocomplete="off" class="layui-input"/>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layui-btn-normal ajax-search"><i class="fa fa-search"></i></button>
				</div>
			</div>
		</form>
	</div>
	<div class="layui-card-body">
		<table class="layui-table layui-form">
			<thead>
			<tr>
				<th>批次号</th>
				<th>类型</th>
				<th>重复数</th>
				<th>失败数</th>
				<th>成功数</th>
				<th>状态</th>
				<th>创建时间</th>
				<th>操作时间</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			{foreach name="list" item="v" empty="$empty"}
			<tr>
				<td>{$v.batch_no}</td>
				<td>{$v.typeName}</td>
				<td>{$v.repeat_num}</td>
				<td>{$v.fail_num}</td>
				<td>{$v.success_num}</td>
				<td>
					{if $v.opt_type == 0}<label>待审核</label>
					{elseif $v.opt_type == 1}<label style="color: #00FF00">已导入</label>
					{elseif $v.opt_type == 2}<label style="color: #af0000">已撤回</label>
					{/if}
				</td>
				<td>{$v.create_time}</td>
				<td>{$v.update_time}</td>
				<td>
					{if $v.opt_type == 0}
						<a onclick="sureImport({$v.type_id}, {$v.batch_no})" class="layui-btn layui-btn-xs layui-btn-normal"><i class="fa fa-edit"></i> 导入</a>
						<a onclick="skipImport({$v.type_id}, {$v.batch_no})" class="layui-btn layui-btn-xs layui-btn-normal"><i class="fa fa-edit"></i> 撤回</a>
					{/if}
				</td>
			</tr>
			{/foreach}
			</tbody>
		</table>
		<div class="page">{$list->render()}</div>
	</div>
</div>
{/block}
{block name="js"}
<script>
	function sureImport(type_id, batchNo) {
		if (type_id === '' || type_id === null || type_id === undefined) {
			layer.msg("类型错误");
		}
		if (batchNo === '' || batchNo === null || batchNo === undefined) {
			layer.msg("请先导入数据");
		}
		var index = layer.msg('导入中，请稍候', {
			icon: 16,
			time: false,
			shade: 0.3
		});
		$.ajax({
			url: '/admin/metadata/sureImport?id=' + type_id + '&batchNo=' + batchNo,
			type: 'post',
			dataType: 'json',
			success: function (result) {
				layer.close(index);
				if (result.code === 1) {
					layer.msg('导入成功');
					location.href = '/admin/metadata/importLogIndex';
				}
			},
			error: function (xhr, state, errorThrown) {
				layer.close(index);
				layer.msg(state + '：' + errorThrown);
			}
		});
	}

	function skipImport(type_id, batchNo) {
		if (type_id === '' || type_id === null || type_id === undefined) {
			layer.msg("类型错误");
		}
		if (batchNo === '' || batchNo === null || batchNo === undefined) {
			layer.msg("请先导入数据");
		}
		$.ajax({
			url: '/admin/metadata/skipImport?id=' + type_id + '&batchNo=' + batchNo,
			type: 'post',
			dataType: 'json',
			success: function (result) {
				if (result.code === 1) {
					layer.msg('撤回成功');
					location.href = '/admin/metadata/importLogIndex';
				}
			},
			error: function (xhr, state, errorThrown) {
				layer.msg(state + '：' + errorThrown);
			}
		});
	}
</script>
{/block}